package models

import (
	"behavior_srv/basic/config"
	"time"
)

// ClickBehavior 用户点击行为
type BehaviorClickRecords struct {
	Id           uint64    `gorm:"column:id;type:bigint UNSIGNED;primaryKey;not null;" json:"id"`
	UserId       int64     `gorm:"column:user_id;type:bigint;comment:用户ID;default:0;" json:"user_id"`                 // 用户ID
	SessionId    string    `gorm:"column:session_id;type:varchar(100);comment:会话ID;not null;" json:"session_id"`      // 会话ID
	Path         string    `gorm:"column:path;type:varchar(255);comment:页面路径;not null;" json:"path"`                  // 页面路径
	PageName     string    `gorm:"column:page_name;type:varchar(100);comment:页面名称;default:NULL;" json:"page_name"`    // 页面名称
	BehaviorType string    `gorm:"column:behavior_type;type:varchar(50);comment:行为类型;not null;" json:"behavior_type"` // 行为类型
	Details      string    `gorm:"column:details;type:text;comment:行为详情;" json:"details"`                             // 行为详情
	ClickTime    time.Time `gorm:"column:click_time;type:datetime(3);comment:点击时间;not null;" json:"click_time"`       // 点击时间
	CreatedAt    time.Time `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt    time.Time `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt    time.Time `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

// TableName 设置表名
func (c *BehaviorClickRecords) TableName() string {
	return "behavior_click_records"
}

// Create 创建点击行为记录
func (c *BehaviorClickRecords) Create() error {
	return config.DB.Create(c).Error
}

// BatchCreate 批量创建点击行为记录
func (c *BehaviorClickRecords) BatchCreate(behaviors []*BehaviorClickRecords) error {
	return config.DB.CreateInBatches(behaviors, 100).Error
}
